package ee.ut.test;

import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.EditText;

public class SearchActivity extends Activity {
	
	public static final String SEARCH_STRING = "searchString";
	public static final String SEARCH_TYPE = "searchType";
	public static final String SEARCH_TYPE_DOC = "Doctor";
	public static final String SEARCH_TYPE_PROF = "Profession";
	
	private EditText searchInput;
	
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.search);
        
        searchInput = (EditText) findViewById(R.id.searchInput);
        
        final Button searchByDoctorButton = (Button) findViewById(R.id.searchByDoctorButton);
        searchByDoctorButton.setOnClickListener(new SearchByDocButtonOnClickListener(SEARCH_TYPE_DOC));
        
        final Button searchByProfButton = (Button) findViewById(R.id.searchByProfButton);
        searchByProfButton.setOnClickListener(new SearchByDocButtonOnClickListener(SEARCH_TYPE_PROF));        
    }
    
    protected final class SearchByDocButtonOnClickListener implements OnClickListener {
    	
    	protected String searchType;
    	
    	protected SearchByDocButtonOnClickListener(String searchType){
    		this.searchType = searchType;
    	}
    	
		@Override
		public void onClick(View v) {
			String searchString = searchInput.getText().toString();
			Intent intent = new Intent(SearchActivity.this, ResultListActivity.class);
			intent.putExtra(SEARCH_STRING, searchString);
			intent.putExtra(SEARCH_TYPE, searchType);
			startActivity(intent);
		}
    }
}
